# encoding: utf-8

module Admin::HistoriesHelper
  def time_filter_tag(filtered_task)
    starttime_str = ""
    endtime_str   = ""
    start_ary     = nil
    str_flag      = false
    _time_tag = ['年', '月', '日', '时']
    if filtered_task.starttime.present?
      start_ary = filtered_task.starttime.split('-')
      start_ary.each_with_index do |str, idx|
        starttime_str += (str + _time_tag[idx])
      end
    end
    if filtered_task.endtime.present?
      filtered_task.endtime.split('-').each_with_index do |str, idx|
        _start_str = start_ary[idx] if start_ary
        if _start_str != str || str_flag
          str_flag = true
          endtime_str += (str + _time_tag[idx])
        end
      end
    end
    "#{starttime_str} #{'~' if starttime_str.present?} #{endtime_str}"
  end
end
